home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 28.7 KB | 997 lines | [TEXT/MPS ] |
- // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
- // UDrawShapes.cp
-
- #ifndef __UOBJECT__
- #include <UObject.h> // work around nested include limitation in CFront
- #endif
-
- #ifndef __USHAPESDOCUMENT__
- #include "UShapesDocument.h"
- #endif
-
- // MacApp
-
- #ifndef __UMENUMGR__
- #include <UMenuMgr.h>
- #endif
-
- #ifndef __UPRINTING__
- #include <UPrinting.h>
- #endif
-
- #ifndef __USCROLLER__
- #include <UScroller.h>
- #endif
-
- #ifndef __UVIEWSERVER__
- #include <UViewServer.h>
- #endif
-
- #ifndef __UWINDOW__
- #include <UWindow.h>
- #endif
-
- #ifndef __USTREAM__
- #include <UStream.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include <UMacAppGlobals.h>
- #endif
-
- // Toolbox
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // DrawShapes
-
- #ifndef __SHAPECOMMANDS__
- #include "ShapeCommands.h"
- #endif
-
- #ifndef __UDRAWSHAPES__
- #include "UDrawShapes.h"
- #endif
-
- #ifndef __USHAPES__
- #include "UShapes.h"
- #endif
-
- #ifndef __USHAPEVIEW__
- #include "UShapeView.h"
- #endif
-
- //----------------------------------------------------------------------------------------
- // Resources
-
- // Menu bars for color and for b&w systems
- #define kColorMenuBar 131
- #define kNonColorMenuBar 132
-
- #define kRainbowArrow 140
-
- #define kPickerPrompt 256
-
- const OSType kDocRsrcKind = 'DSTA'; // Resource type for document state
- const short kDocStateID = 1; // Resource id for document state
-
- // Windows
-
- const short kShapeWindowRSRCID = 1005; // Windows used by documents in the application
-
- const short kShapeViewRSRCID = 1006; // Resource id for the shape view template,
- // used when printing & using template views
-
- const short kToolsPaletteRSRCID = 1007; // Resource id for the floating window with
- // tools palette
-
- const short kPatternsPaletteRSRCID = 1008; // Resource id for the floating window with
- // patterns palette
-
- // Menus
- const short mTools = 5; // the Tools menu resource id
- const short mPatterns = 6; // the Patterns menu resource id
- const short mColor = 7; // the Color menu resource id
- const short mMoreDebug = 8; // Menu number for the "More Debug" menu
-
-
- // Command Numbers
-
- #define cArrow 1100
- #define cBox 1101
- #define cCircle 1102
- #define cHBox 1103
-
- //----------------------------------------------------------------------------------------
- // Miscellaneous
-
- const short kStaggerAmount = 16; // Amount to stagger windows by
-
-
- //========================================================================================
- // Functions called by FirstThat
- // typedef Boolean (*TestShapeType)(TShape* item, void* staticLink);
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- Boolean IsShapeSelected(TShape* shape, void* /*staticLink*/)
- {
- return shape->IsSelected();
- }
-
- //========================================================================================
- // Functions called by Each, EachShapeDo, etc.
- // typedef void(* DoToShapeType)(TShape* item, void* staticLink);
-
- //----------------------------------------------------------------------------------------
- struct CheckShapeRec
- {
- CPoint& fqdPt;
- TShape* fShapeUnderMouse;
-
- CheckShapeRec(CPoint& qdPt);
- };
-
- #pragma segment ASelCommand
-
- CheckShapeRec::CheckShapeRec(CPoint& qdPt) :
- fqdPt(qdPt)
- {
- fShapeUnderMouse = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void CheckShape(TShape* shape, void* staticLink)
- {
- // staticLink is really a CheckShapeRec*
- CheckShapeRec* checkShapePtr = (CheckShapeRec*)staticLink;
- CRect extent;
- shape->GetFrame(extent);
- if (PtInRect(checkShapePtr->fqdPt, extent))
- checkShapePtr->fShapeUnderMouse = shape;
- }
-
- //----------------------------------------------------------------------------------------
- struct DrawShapeRec
- {
- CRect& fqdArea;
- Boolean fDragging;
-
- DrawShapeRec(CRect& qdArea, Boolean dragging);
- };
-
- #pragma segment ARes
-
- DrawShapeRec::DrawShapeRec(CRect& qdArea, Boolean dragging) :
- fqdArea(qdArea),
- fDragging(dragging)
- { }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void DrawShape(TShape* shape, void* staticLink)
- {
- // staticLink is really a DrawShapeRec*
- DrawShapeRec* drawShapePtr = (DrawShapeRec*)staticLink;
-
- CRect r;
- CRect extent;
- shape->GetFrame(extent);
- if (!(drawShapePtr->fDragging && shape->IsSelected()) &&
- SectRect(extent, drawShapePtr->fqdArea, r))
- shape->Draw();
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
-
- void FreeIfShape(TShape* shape, void* /*staticLink*/)
- {
- FreeIfObject(shape);
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void WriteShape(TShape* shape, void* staticLink)
- {
- // staticLink is really a TStream*
- TStream* aStream = (TStream*)staticLink;
-
- aStream->WriteStreamObject(shape, kNoStandardObject);
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void DeselShape(TShape* shape, void* /*staticLink*/)
- {
- shape->SetSelected(false);
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void DoRestore(TShape* shape, void* staticLink)
- {
- // staticLink is really a TShapeView*
- TShapeView* shapeView = (TShapeView*)staticLink;
-
- Boolean wantInval = shape->IsSelected() || shape->WasSelected();
- shape->SetIsWasSelected();
- if (wantInval)
- shapeView->InvalShape(shape);
- }
-
- //----------------------------------------------------------------------------------------
- struct HiliteShapeRec
- {
- TShapeView* fShapeView;
- HLState fFromHL;
- HLState fToHL;
-
- HiliteShapeRec(TShapeView* shapeView, HLState fromHL, HLState toHL);
- };
-
- #pragma segment ShapeRes
-
- HiliteShapeRec::HiliteShapeRec(TShapeView* shapeView, HLState fromHL, HLState toHL) :
- fShapeView(shapeView),
- fFromHL(fromHL),
- fToHL(toHL)
- { }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void HiliteShape(TShape* shape, void* staticLink)
- {
- // staticLink is really a HiliteShapeRec*
- HiliteShapeRec* hlRecPtr = (HiliteShapeRec*)staticLink;
-
- if (shape->IsSelected() && !hlRecPtr->fShapeView->IsDragging())
- shape->Highlight(hlRecPtr->fFromHL, hlRecPtr->fToHL, hlRecPtr->fShapeView);
- }
-
- //----------------------------------------------------------------------------------------
- struct SaveSelRec
- {
- TShapeView* fShapeView;
- Boolean fAndInval;
-
- SaveSelRec(TShapeView* shapeView, Boolean andInval);
- };
-
- #pragma segment ShapeRes
-
- SaveSelRec::SaveSelRec(TShapeView* shapeView, Boolean andInval) :
- fShapeView(shapeView),
- fAndInval(andInval)
- { }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void SaveSel(TShape* shape, void* staticLink)
- {
- // staticLink is really a SaveSelRec*
- SaveSelRec* selRecPtr = (SaveSelRec*)staticLink;
-
- shape->SetWasIsSelected();
- if (shape->WasSelected() && selRecPtr->fAndInval)
- selRecPtr->fShapeView->InvalShape(shape);
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void SelectIt(TShape* shape, void* staticLink)
- {
- // staticLink is really a TShapeView*
- TShapeView* shapeView = (TShapeView*)staticLink;
-
- if (!shape->IsSelected())
- {
- shape->SetSelected(true);
- shape->Highlight(hlOff, hlOn, shapeView);
- }
- }
-
- //----------------------------------------------------------------------------------------
- struct TestShapesRec
- {
- Boolean& fAnySelection;
- Boolean& fAnyShapes;
- Boolean fDocFiltering;
-
- TestShapesRec(Boolean& anySelection, Boolean& anyShapes, Boolean docFiltering);
- };
-
- #pragma segment ARes
-
- TestShapesRec::TestShapesRec(Boolean& anySelection, Boolean& anyShapes, Boolean docFiltering) :
- fAnySelection(anySelection),
- fAnyShapes(anyShapes),
- fDocFiltering(docFiltering)
- { }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TestShapes(TShape* shape, void* staticLink)
- {
- // staticLink is really a TestShapesRec*
- TestShapesRec* testShapesPtr = (TestShapesRec*)staticLink;
-
- testShapesPtr->fAnySelection |= shape->IsSelected();
- testShapesPtr->fAnyShapes |= testShapesPtr->fDocFiltering;
- testShapesPtr->fAnyShapes |= shape->WasSelected();
- }
-
- //----------------------------------------------------------------------------------------
- struct TestCursorRec
- {
- Boolean& fCursorSet;
- CPoint fqdPoint;
- RgnHandle fCursorRegion;
-
- TestCursorRec(Boolean& cursorSet, CPoint qdPoint, RgnHandle cursorRegion);
- };
-
- #pragma segment ShapeRes
-
- TestCursorRec::TestCursorRec(Boolean& cursorSet, CPoint qdPoint, RgnHandle cursorRegion) :
- fCursorSet(cursorSet),
- fqdPoint(qdPoint),
- fCursorRegion(cursorRegion)
- { }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TestShapeCursor(TShape* shape, void* staticLink)
- {
- // staticLink is really a TestCursorRec*
- TestCursorRec* testPtr = (TestCursorRec*)staticLink;
-
- if (!testPtr->fCursorSet)
- {
- CRect extent;
- shape->GetFrame(extent);
- if (PtInRect(testPtr->fqdPoint, extent))
- {
- UseROMMap(true);
- SetCursor(*GetCursor(plusCursor));
- RectRgn(testPtr->fCursorRegion, extent);
- testPtr->fCursorSet = true;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- struct SurveyRec
- {
- Boolean fSelecteesOnly;
- short& fNumberOfShapes;
- CRect& fCombinedExtent;
-
- SurveyRec(Boolean selecteesOnly, short& numberOfShapes, CRect& combinedExtent);
- };
-
- SurveyRec::SurveyRec(Boolean selecteesOnly, short& numberOfShapes, CRect& combinedExtent) :
- fSelecteesOnly(selecteesOnly),
- fNumberOfShapes(numberOfShapes),
- fCombinedExtent(combinedExtent)
- { }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void UnionizeShapes(TShape* shape, void* staticLink)
- {
- // staticLink is really a SurveyRec*
- SurveyRec* surveyPtr = (SurveyRec*)staticLink;
-
- if (shape->IsSelected() || !surveyPtr->fSelecteesOnly)
- {
- CRect extent;
- shape->GetFrame(extent);
- surveyPtr->fNumberOfShapes++;
- if (surveyPtr->fNumberOfShapes > 1)
- UnionRect(extent, surveyPtr->fCombinedExtent, surveyPtr->fCombinedExtent);
- else
- surveyPtr->fCombinedExtent = extent;
- }
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void ShapeBeInView(TShape* shape, void* staticLink)
- {
- shape->BeInView((TShapeView*)staticLink);
- }
-
- //========================================================================================
- // CLASS TShapeDocument
- //========================================================================================
- #undef Inherited
- #define Inherited TFileBasedDocument
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TShapeDocument, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TShapeDocument::TShapeDocument()
- {
- fShapeView = NULL;
- fShapeList = NULL;
-
- fSavePrintInfo = true;
- fSaveUserSelection = false;
-
- fReopening = false;
- fFiltering = false;
- fReplaceCommand = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::IShapeDocument
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TShapeDocument::IShapeDocument(TFile* itsFile)
- {
- MAVolatileInit(TShapeList*, shapeList, NULL);
-
- this->IFileBasedDocument(itsFile, kShapeClipType);
-
- FailInfo fi;
- Try(fi)
- {
- shapeList = new TShapeList;
- shapeList->IList();
- fShapeList = shapeList;
- fi.Success();
- }
- else
- {
- FreeIfObject(shapeList);
- this->Free();
- fi.ReSignal();
- }
- #if qDebug
- fShapeList->SetEltType("TShape");
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::Free
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
-
- void TShapeDocument::Free() // Override
- {
- this->FreeData();
- fShapeList = (TShapeList*)FreeListIfObject(fShapeList);
-
- Inherited::Free();
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::Free
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
-
- void TShapeDocument::FreeData() // Override
- {
- if (fShapeList)
- {
- this->EachShapeDo(&FreeIfShape, NULL);
- fShapeList->DeleteAll();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::AddShape
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::AddShape(TShape* shape)
- {
- fShapeList->InsertLast(shape);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::DeleteShape
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::DeleteShape(TShape* shape)
- {
- fShapeList->Delete(shape);
- FreeIfObject(shape);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::EachShapeDo
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::EachShapeDo(DoToShapeType DoToShape, void* staticLink)
- {
- fShapeList->Each(DoToShape, staticLink);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::EachShapeMaybeDo
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::EachShapeMaybeDo(DoToShapeType DoToShape, void* staticLink)
- {
- CShapeIterator iter(fShapeList);
-
- for (TShape* shape = iter.FirstShape(); iter.More(); shape = iter.NextShape())
- {
- if (!fFiltering || !shape->WasSelected())
- DoToShape(shape, staticLink);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::EachPotentialShapeDo
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::EachPotentialShapeDo(DoToShapeType DoToShape, void* staticLink)
- {
- this->EachShapeDo(DoToShape, staticLink);
- if (fReplaceCommand)
- fReplaceCommand->EachNewShapeDo(DoToShape, staticLink);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::EachVirtualShapeDo
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::EachVirtualShapeDo(DoToShapeType DoToShape, void* staticLink)
- {
- // EachVirtualShape iterates through only those shapes that appear
- // to be present at the moment to the USER, given the
- // UNDO/REDO status of the last command. Thus it iterates
- // through some but possibly not all of the shapes in the
- // document, and possibly also through not-yet-in-the-document pastees
-
- this->EachShapeMaybeDo(DoToShape, staticLink);
- if (fReplaceCommand)
- fReplaceCommand->EachNewShapeDo(DoToShape, staticLink);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::FirstSelectedShape
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- TShape* TShapeDocument::FirstSelectedShape()
- {
- TShape* shape = fShapeList->FirstThat(&IsShapeSelected, NULL);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::AddPrintHandlerToView
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TShapeDocument::AddPrintHandlerToView(TView* theView)
- {
- TStdPrintHandler* printHandler = new TStdPrintHandler;
- printHandler->IStdPrintHandler(this, theView, !kSquareDots, !kFixedSize, !kFixedSize);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::DoMakeViews
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TShapeDocument::DoMakeViews(Boolean forPrinting) // Override
- {
- if (forPrinting)
- {
- if (qTemplateViews)
- {
- TShapeView* shapeView = (TShapeView*)gViewServer->DoCreateViews(this, NULL, kShapeViewRSRCID, gZeroVPt);
- FailNIL(shapeView);
- fShapeView = shapeView;
- this->AddPrintHandlerToView(fShapeView);
- }
- else
- this->CreateProceduralShapeView();
- }
-
- // not for printing
- else
- {
- TWindow* aWindow = NULL;
- if (qTemplateViews)
- {
- aWindow = gViewServer->NewTemplateWindow(kShapeWindowRSRCID, this);
- FailNIL(aWindow);
- fShapeView = (TShapeView*)aWindow->FindSubView(kShapeClipType);
- FailNIL(fShapeView);
- this->AddPrintHandlerToView(fShapeView);
- }
- else
- {
- this->CreateProceduralShapeView();
- aWindow = gViewServer->NewSimpleWindow(kShapeWindowRSRCID,
- kWantHScrollBar, kWantVScrollBar,
- this, fShapeView);
- FailNIL(aWindow);
- }
-
- if (fReopening)
- this->RestoreWindow(aWindow);
- else
- {
- aWindow->AdaptToScreen();
- CPoint stagger(kStaggerAmount, kStaggerAmount);
- aWindow->SimpleStagger(stagger, gStaggerCount);
- }
-
- // Set window's resize limits so it can't become wider than the shapeView's edge
- CPoint minSize, maxSize;
- minSize = aWindow->fResizeLimits[topLeft];
- maxSize = aWindow->fResizeLimits[botRight];
- maxSize.h = (short)Min(fShapeView->fSize.h + kSBarSizeMinus1, maxSize.h);
- aWindow->SetResizeLimits(minSize, maxSize);
- }
-
- ShapesBeInView(fShapeView);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::RestoreWindow
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TShapeDocument::RestoreWindow(TWindow* aWindow)
- {
- // Restore the window and scroller using the settings in the document's fDocState field
- aWindow->Locate(fDocState.theLocation, false);
- aWindow->Resize(fDocState.theSize, false);
- aWindow->ForceOnScreen();
- fShapeView->GetScroller(false)->SetLocalOrigin(fDocState.theScrollPosition, false);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::CreateProceduralShapeView
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TShapeDocument::CreateProceduralShapeView()
- {
- TShapeView* shapeView = new TShapeView;
- shapeView->IShapeView(this, false);
- fShapeView = shapeView;
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::DoSetupMenus
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TShapeDocument::DoSetupMenus() // Override
- {
- Inherited::DoSetupMenus();
-
- for (CommandNumber i=cArrow; i <= cHBox; i++)
- Enable(i, true);
-
- Enable(1901, true);
- Enable(1902, true);
- Enable(1903, true);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::DoNeedDiskSpace
- // Doc file has the following format:
- // Data Fork:
- // (a) kSizePrintInfo (120 bytes) => PrintInfo
- // (b) The rest => The shapes themselves
- //
- // Resource Fork:
- // (a) SIZEOF(DocState) => DocState (rsrc type: 'DSTA', number: 1)
- //
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TShapeDocument::DoNeedDiskSpace(TFile* itsFile,
- long& dataForkBytes,
- long& rsrcForkBytes) // Override
- {
- // Get Print record requirements
- Inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
-
- dataForkBytes = dataForkBytes + fShapeList->GetSize() + sizeof(ShapeData);
- rsrcForkBytes = rsrcForkBytes + kRsrcTypeOverhead + kRsrcOverhead + sizeof(DocState);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::DoRead
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void TShapeDocument::DoRead(TFile* aFile, Boolean forPrinting) // Override
- {
- Inherited::DoRead(aFile, forPrinting);
-
- // Read in doc data
- TFileStream* aFileStream = new TFileStream;
- aFileStream->IFileStream(aFile);
- TContext* itsContext = new TContext;
- itsContext->IContext();
- aFileStream->SetContext(itsContext);
- this->ReadFrom(aFileStream);
- FreeIfObject(aFileStream);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::ReadFrom
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void TShapeDocument::ReadFrom(TStream* aStream) // Override
- {
- Inherited::ReadFrom(aStream);
-
- // Read in the doc state
- aStream->ReadBytes(&fDocState, sizeof(DocState));
-
- // Read in the shapes
- TShape* newShape = NULL;
- for (short i=0; i < fDocState.theNumberOfShapes; i++)
- {
- if (aStream->ReadStreamObject((TObject * &)newShape))
- this->AddShape(newShape);
- #if qDebug
- else
- fprintf(stderr, "###TShapeDocument::ReadFrom: Can’t read in a shape");
- #endif
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::DoWrite
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TShapeDocument::DoWrite(TFile* aFile, Boolean makingCopy) // Override
- {
- Inherited::DoWrite(aFile, makingCopy);
-
- TFileStream* aFileStream = new TFileStream;
- aFileStream->IFileStream(aFile);
- TContext* itsContext = new TContext;
- itsContext->IContext();
- aFileStream->SetContext(itsContext);
- this->WriteTo(aFileStream);
- FreeIfObject(aFileStream);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::WriteTo
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TShapeDocument::WriteTo(TStream* aStream) // Override
- {
- short numberOfShapes;
- CRect dummyRect;
- DocState localDocState;
-
- Inherited::WriteTo(aStream);
-
- // Write out the doc state
- this->SurveyShapes(false, numberOfShapes, dummyRect);
- TWindow* window = (TWindow*)fWindowList->First();
- localDocState.theLocation = window->fLocation;
- localDocState.theSize = window->fSize;
- localDocState.theScrollPosition = fShapeView->GetScroller(false)->fTranslation;
- localDocState.theNumberOfShapes = numberOfShapes;
- aStream->WriteBytes(&localDocState, sizeof(DocState));
-
- // Write out the shapes
- this->EachVirtualShapeDo(&WriteShape, (void*)aStream);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::ShapesAsPict
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- PicHandle TShapeDocument::ShapesAsPict(TList* aShapeList)
- {
- TShapeView* clipShapeView;
- TShapeDocument* clipShapeDoc;
- TShape* aNewShape;
-
- clipShapeDoc = new TShapeDocument;
- clipShapeDoc->IShapeDocument(NULL);
-
- clipShapeView = new TShapeView;
- clipShapeView->IShapeView(clipShapeDoc, true);
- VPoint itsSize(fShapeView->fSize.h, fShapeView->fSize.v);
- clipShapeView->Resize(itsSize, kDontRedraw);
- clipShapeDoc->fShapeView = clipShapeView;
-
- for (ArrayIndex i=0; i < aShapeList->GetSize(); i++)
- {
- aNewShape = (TShape*)aShapeList->At(i)->Clone();
- clipShapeDoc->AddShape(aNewShape);
- }
-
- FreeIfObject(clipShapeDoc); // Get rid of temp document
- return clipShapeView->AsPict();
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::SurveyShapes
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::SurveyShapes(Boolean selecteesOnly, short& numberOfShapes, CRect& combinedExtent)
- {
- numberOfShapes = 0;
- combinedExtent = gZeroRect;
- SurveyRec surveyRecord(selecteesOnly, numberOfShapes, combinedExtent);
-
- this->EachVirtualShapeDo(&UnionizeShapes, (void*)&surveyRecord);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::ShapeUnderMouse
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- TShape* TShapeDocument::ShapeUnderMouse(CPoint qdPt)
- {
- CheckShapeRec checkRec(qdPt);
- EachVirtualShapeDo(&CheckShape, (void*)&checkRec);
- return checkRec.fShapeUnderMouse;
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::DeselectShapes
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::DeselectShapes()
- {
- EachPotentialShapeDo(&DeselShape, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::RestoreSelection
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::RestoreSelection(TShapeView* shapeView)
- {
- EachPotentialShapeDo(&DoRestore, (void*)shapeView);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::DrawShapes
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::DrawShapes(CRect& qdArea, Boolean dragging)
- {
- DrawShapeRec drawRec(qdArea, dragging);
- EachVirtualShapeDo(&DrawShape, (void*)&drawRec);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::HiliteShapes
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::HiliteShapes(TShapeView* shapeView, HLState fromHL, HLState toHL)
- {
- HiliteShapeRec hlShapeRec(shapeView, fromHL, toHL);
- EachVirtualShapeDo(&HiliteShape, (void*)&hlShapeRec);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::SaveSelection
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::SaveSelection(TShapeView* shapeView, Boolean andInval)
- {
- SaveSelRec saveRec(shapeView, andInval);
- EachPotentialShapeDo(&SaveSel, (void*)&saveRec);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::SelectAllShapes
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::SelectAllShapes(TShapeView* shapeView)
- {
- EachVirtualShapeDo(&SelectIt, shapeView);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::CursorInShape
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- Boolean TShapeDocument::CursorInShape(CPoint qdPoint, RgnHandle cursorRegion)
- {
- Boolean cursorSet = false;
- TestCursorRec testRec(cursorSet, qdPoint, cursorRegion);
- EachVirtualShapeDo(&TestShapeCursor, (void*)&testRec);
-
- return cursorSet;
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::AnyShapesSelected
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::AnyShapesSelected(Boolean& anySelection, Boolean& anyShapes)
- {
- TestShapesRec testRec(anySelection, anyShapes, IsFiltering());
- EachVirtualShapeDo(&TestShapes, (void*)&testRec);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::ShapesBeInView
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeRes
-
- void TShapeDocument::ShapesBeInView(TShapeView* shapeView)
- {
- EachShapeDo(&ShapeBeInView, shapeView);
- }
-
- //----------------------------------------------------------------------------------------
- // TShapeDocument::MakeClipView: Launch a view to represent the data found
- // in the Clipboard at application start-up time, or when switching back in, or when
- // returning from a Desk Accessory.
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- TView* TShapeDocument::MakeClipView()
- {
- TShapeView* clipShapeView = new TShapeView;
- clipShapeView->IShapeView(this, true);
-
- fShapeView = clipShapeView;
-
- fShapeView->ReadFromDeskScrap();
-
- return clipShapeView;
- }
-
-